<?php

class Admin_Forms_AddMenuForm extends Zend_Form{
	private $_messagesError = null;

	public function __construct($option=null){
        $this->setAction('')
				->setMethod('POST')
				->setAttrib('enctype', 'multipart/form-data')
				->setAttrib('class', 'form-horizontal')
                                ->setAttrib('style','float:left')
			    ->setAttrib('name', 'addMenu-form');
		$menuname = $this->createElement('text', 'name');
		$menuname->addValidator('NotEmpty');
		$menuname->getValidator('NotEmpty')->getMessages('Xin điền tên menu');
		$menuname->setRequired ( true )
		->addFilter('StringTrim')
		->setAttrib('class', 'input-xlarge')
		->setLabel('Menu Name');
                
               //load category
		
		$menulist = new Zend_Form_Element_Select('menulist');
		$menulist->addMultiOption(0,'Không có');
		$menulist->setLabel('Thuộc menu')
		->setRequired(true);
		foreach ($option as $data) {
			$menulist->addMultiOption($data['id'], $data['name']);
		}
		$link_menu = $this->createElement('text', 'link');
		$link_menu
		->addFilter('StringTrim')
		->setAttrib('class', 'input-xlarge')
		->setLabel('Link');
		$ordering = $this->createElement('text', 'ordering');
		$ordering
		->addFilter('StringTrim')
		->setAttrib('class', 'input-xlarge')
		->setLabel('Sắp xếp thứ tự');
		//
                $controller = $this->createElement('text', 'controller_add');
		$controller->addValidator('NotEmpty');
		$controller->getValidator('NotEmpty')->getMessages('Xin điền tên menu');
		$controller->setRequired ( true )
		->addFilter('StringTrim')
		->setAttrib('class', 'input-xlarge')
		->setLabel('Controller');
		$allowed_tags = array(
				'a' =>	array('href', 'title'),
				'strong',
				'img'	=>	array('src', 'alt'),
				'ul',
				'ol',
				'li',
				'em',
				'u',
				'strike');
		
		$content = new Zend_Form_Element_Textarea('feature');
		$content->setLabel('Nội dung')
		->setAttrib('rows', 12)
		->setAttrib('cols', 40)
		->setRequired(true)
		->addFilter('StringTrim')
		->addFilter('StripTags', $allowed_tags);
		$content->setAttrib('class','ckeditor');
// 		$feature =$this->createElement('textarea','feature');
// 		$feature->setRequired ( true )
// 		->addFilter('StringTrim')
// 		->setAttrib('class', 'input-xlarge')
// 		->setAttrib('style', 'height:60px')
// 		->setLabel('Thông số');
		
		
		$avatar =$this->createElement("file", "avatar");
		$avatar
		 	  ->setLabel('Xin chọn ảnh nội dung')
		 	  ->setDestination(APPLICATION_PATH.'/../public/imagesnote/note/');
		$avatar->addValidator(new Zend_Validate_File_Extension(array('gif,png,jpg')));
		$avatar->addValidator(new Zend_Validate_File_FilesSize(array('min'=>1,'max'=>10000000,'bytestring'=>true)));
	    $avatar->setAttrib('class','fileupload fileupload-new');
		$cancel = $this->createElement('button', 'cancel',array('label'	=> 'Hủy bỏ','class'=>'btn btn-inverse','onclick'	=> 'windown:location = "' .'/admin/setting/list-menu'. '"'));
		$reset = $this->createElement('reset','reset',array('label'	=> 'Reset','class'=>'btn'));
		$submit = $this->createElement('submit','submit',array ('label' => 'Thêm'));
		
                $submit->setAttrib('class', 'btn btn-primary');		
                $this->addElement($menuname);
		//$this->addElement(new Element_CategorySelect('CatID'));
		$this->addElement($menulist)
		->addElement($link_menu)
                ->addElement($ordering)
                ->addElement($controller)
		->addElement($cancel)
		->addElement($reset)
		->addElement($submit);
		$this->setDecorators(array('FormElements',array('HtmlTag',array('tag'	=> 'div','width'=>'100%')),'form'));
		$this->setElementDecorators(array(
				'ViewHelper',
				'Errors',
				'Description',
				array(
						array('data'	=> 'HtmlTag'),
						array('tag'		=> 'div','class'	=> 'controls')),
				array('label',
						array('class'	=> 'control-label','requiredSuffix'=>'(*)')),
				array(
						array('row'	=> 'HtmlTag',),
						array('class'=>'control-group ')
				),
				array(
						array('ErrorsDiv' => 'HtmlTag'),
						array('tag' => 'span', 'placement' => Zend_Form_Decorator_Abstract::APPEND)
				)
		)
		);
		
//		$this->getElement('avatar')->setDecorators(
//				array(
//						'File',
//						'Errors',
//						array(
//						array('data'	=> 'HtmlTag'),
//						array('tag'		=> 'div','class'	=> 'controls')),
//				array('label',
//						array('class'	=> 'control-label','requiredSuffix'=>'(*)')),
//				array(
//						array('row'	=> 'HtmlTag',),
//						array('class'=>'control-group ')
//				),
//				array(
//						array('ErrorsDiv' => 'HtmlTag'),
//						array('tag' => 'span', 'placement' => Zend_Form_Decorator_Abstract::APPEND)
//				)
//				)
//		);
		$submit->setDecorators(array(
				'ViewHelper',
		));
		$reset->setDecorators(array(
				'ViewHelper',
		));
		$cancel->setDecorators(array(
				'ViewHelper',
		)
		);
		$this->addDisplayGroup(array('submit','reset','cancel'),'action');
		$action = $this->getDisplayGroup('action');
		$action->setDecorators(array(
				'FormElements',
				'Fieldset',
				array('HtmlTag',array('tag'=>'div','class'	=> 'form-actions'))
		));
	}
	public function isError(){
		if (count($this->_messagesError)>0){
			return true;
		}
		else
			return false;
	}
	
	//tra ve mot mang cac loi
	public function getMessagesError(){
		return $this->_messagesError;
	}
        
}   
?>
